package fileio;

import java.io.BufferedReader;
import java.io.FileReader;

public class EDITest {

	public static void main(String[] args) {
		// printDNH_Ingram();
		printCBD();
	}

	private static void printCBD() {
		String[] files = {
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01172011042100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10312010192058.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12062010172031.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12262010202051.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01022011232056.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01232011192049.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10242010082041.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11212010192100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12142010142033.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01232011082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11072010082043.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11082010042141.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11302010172030.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12202010042051.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01162011082041.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10242010222050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11222010142034.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11282010202100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12122010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01092011082036.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10172010232108.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11082010172043.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11282010082035.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12212010082027.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11212010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12122010232053.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12192010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12292010162032.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11142010222058.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11232010082032.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11142010082050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12052010212128.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12262010082050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01092011182059.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10102010182116.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10172010082036.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10312010082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11162010202036.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12052010082040.txt" };

		for (int i = 0; i < files.length; i++) {
			String fileName = files[i];

			System.out.println(fileName);
			BufferedReader br = null;
			try {
				br = new BufferedReader(new FileReader(fileName));
				int lineNum = 0;

				String line;
				String currentCustomer = null;
				while (null != (line = br.readLine())) {
					++lineNum;

					if (line.startsWith("H")) {
						currentCustomer = line.substring(1, 12).trim();
					}

					if (isCBD(currentCustomer)) {
						if (line.startsWith("D76")) {
							if (line.contains("-"))
								;// System.out.println(lineNum + " : " + line);
							else
								System.out.println(lineNum + " : " + line);
						}
					}
					if (line.startsWith("UIT")) {
						if (line.contains("-") || line.contains("("))
							; // System.out.println(line);
					}
				}

				br.close();

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	private static boolean isCBD(String customer) {
		String[] customers = { "0001810004", "0001811041", "0001820434",
				"0006267026" };

		if (customer == null)
			return false;

		for (String name : customers) {

			if (customer.equals(name))
				return true;
		}

		return false;
	}

	private static void printDNH_Ingram() {
		String[] files = {
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03072011022059.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_04032011082039.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08302010052120.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11142010222058.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08292010082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09122010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12052010212128.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11142010082050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12262010082050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02072011042107.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01092011082036.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03142011040120.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03272011082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07252010172308.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08012010162239.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08162010162031.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09192010172111.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10102010082037.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10172010232108.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11282010082035.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01022011082133.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01192011182040.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01162011082041.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03282011022111.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07112010082109.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07252010082151.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10242010222050.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11282010202100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12122010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01172011042100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02162011100404.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02272011082135.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_04042011022109.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09122010232047.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08152010112104.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09262010182104.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10312010192058.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12262010202051.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01022011232056.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01192011192027.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01232011192049.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03062011082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07112010142120.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07182010142321.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10242010082041.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_04102011082043.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11212010192100.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08082010082104.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02202011092059.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01132011152030.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01232011082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02132011082039.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03132011080101.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03202011082053.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07042010082107.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08222010182046.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09052010082040.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10032010182110.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10032010092107.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11082010042141.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11072010082043.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12202010042051.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01302011172040.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01092011182059.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01142011102029.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02062011082035.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02142011042059.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02272011222107.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09192010092043.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09262010082041.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10102010182116.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07182010082112.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10172010082036.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_10312010082042.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08012010082128.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12052010082040.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_02212011042104.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01102011142028.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_03212011022134.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_07042010212222.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08082010172345.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_08222010082037.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_09062010042106.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_11212010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12122010232053.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_12192010082038.txt",
				"D:\\FTP\\wwwroot\\edi_files\\sap867rs_01302011082047.txt" };

		for (int i = 0; i < files.length; i++) {
			String fileName = files[i];

			System.out.println(fileName);
			BufferedReader br = null;
			try {
				br = new BufferedReader(new FileReader(fileName));
				int lineNum = 0;

				String line;
				while (null != (line = br.readLine())) {
					++lineNum;

					if (line.startsWith("D39") || line.startsWith("D76")
							|| line.startsWith("D32")) {
						if (line.contains("-") || line.contains("("))
							System.out.println(lineNum + " : " + line);
					}

					if (line.startsWith("UIT")) {
						if (line.contains("-") || line.contains("("))
							System.out.println(line);
					}

				}

				br.close();

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
